<?php
/**
 * Front Controller Applications
 */
include_once 'classes/ControllerQuestion.php';
include_once 'classes/ControllerUsers.php';
include_once 'classes/AuthUser.php';
define('SMARTY_DIR','libs/');
require(SMARTY_DIR.'Smarty.class.php');

class FrontController
{ 
	private $post;
	private $get;
	protected $smarty = null;
	private $typemvc;
	public $typecontroll;
	public $contr;
	
	public function __construct($get, $post)
	{
		$this->get = $get;
		$this->post = $post;
		$this->typemvc = MVC;
	}
				
	/**
	 * 
	 * Determine which model to use
	 * 
	 * @param $listquestion array questions and answer
	 * @param $questionnoreply array number Question unanswered
	 * @param $post array answer user
	 */
	public function mvcview($arrayData)
	{
		if ($this->typemvc == 'smarty')
		{   
			$this->smarty = new Smarty();
			$this->smarty->template_dir='tpl/templates/';
			$this->smarty->compile_dir='tpl/templates_c/';
			$this->smarty->config_dir='tpl/configs/';
			$this->smarty->cache_dir='tpl/cache/';
			$this->smarty->caching = true;
			$this->smarty->cache_lifetime = 1;
			//data transfer object Smarty
			if ($arrayData != 'login')
			{
				foreach($arrayData as $key => $value) 
	 			{ 
	   				$this->smarty->assign($key, $value);
	  			} 
			}
			$this->smarty->display("index.tpl");
			
		}
		else 
		{   
			if ($this->typecontroll == 'Question')
			{
				foreach($arrayData as $key => $value) 
	 			{	
	 				$this->$key = $value;
	 			}
			}
			else 
			{	
				$this->messagedisplay = $arrayData;
			}
			include_once 'views/index.html';
		}
	}
	
	public function parseGet()
	{
		$authUsers = new AuthUser($this->get);
		$this->typecontroll = $authUsers->authUser($this->get);
		//add name using controller 
		$namecontrol = 'Controller'.$this->typecontroll;
		
		$control = new $namecontrol();
		$control->determinantPage($this->post, $this->get);
		$this->mvcview($control->getMvcData());
	}
}